﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Web.Security;
using BusinessLogic;

namespace DataAccessLogic
{
    public static class StateDataAccess 
    {
        #region Methods
        public static State BindDataToState(DataRow row)
        {
            return FormattedCodeTableDataAccess.BindRowToFormattedCodeTable<State>(row);
        }

        public static Guid Create(State state)
        {
            Guid id = Guid.Empty;
            
            if(state != null)
            {
                id = FormattedCodeTableDataAccess.Create(StoredProcedures.USP_STATEFORMATTEDTYPECODE_CREATE, state.Description, state.Abbreviation);
            }

            return id;
        }

        public static void Delete(State state)
        {
            Delete(state.ID);
        }

        public static void Delete(Guid id)
        {
            FormattedCodeTableDataAccess.Delete(StoredProcedures.USP_STATEFORMATTEDTYPECODE_DELETE, id);
        }

        public static DataTable GetAll()
        {
            return FormattedCodeTableDataAccess.GetAll(StoredProcedures.USP_STATEFORMATTEDTYPECODE_GETALL);
        }

        public static State GetByID(Guid id)
        {
            DataRow row = FormattedCodeTableDataAccess.GetByID(StoredProcedures.USP_STATEFORMATTEDTYPECODE_GETBYID, id);

            if (row != null)
            {
                return StateDataAccess.BindDataToState(row);
            }

            return null;
        }
        #endregion
    }
}